home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / ColorSync SDK / Sample Code / CSDemo 2.1 / CSDemoSources / winTables.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-13  |  8.4 KB  |  298 lines  |  [TEXT/CWIE]

  1. #include "appGlobals.h"
  2. #include "appMenus.h"
  3. #include "appErrors.h"
  4.  
  5. #include "win.h"
  6. #include "winTables.h"
  7.  
  8. #include "winPictDoc.h"
  9. #include "winAbout.h"
  10. #include "winProfile.h"
  11. #include "winProfileGetSet.h"
  12. #include "winProfList.h"
  13. #include "winProfListGetSet.h"
  14. #include "winProfID.h"
  15. #include "winProfIDGetSet.h"
  16.  
  17.  
  18. /**\
  19. |**| ==============================================================================
  20. |**| PRIVATE FUNCTION PROTOTYPES
  21. |**| ==============================================================================
  22. \**/
  23. void winUpdateMenusDefault    ( winHandle win ) ;
  24. void winMenuDefault            ( winHandle win, long menuResult, Boolean *didit ) ;
  25. void DoNewCommand            ( void ) ;
  26. void DoAboutBoxCommand        ( void ) ;
  27. void DoDefaultProfCommand    ( void ) ;
  28. void DoProfListCommand        ( OSType profileClass ) ;
  29.  
  30.  
  31. /**\
  32. |**| ==============================================================================
  33. |**| PUBLIC GLOBALS
  34. |**| ==============================================================================
  35. \**/
  36. short                 gAllocProcMapCount = 3 ;
  37. AllocProcMapRec     gAllocProcMap[3] = {
  38.                                         { 'PICT', winAllocPictDoc, true, false },
  39.                                         { 'prof', winAllocProfile, false, false },
  40.                                         { 'pfid', winAllocProfID,  false, false }
  41.                                        };
  42. UpdateMenusProcPtr    gDefaulltUpdateMenusProc = winUpdateMenusDefault ;
  43. MenuProcPtr            gDefaulltMenuProc = winMenuDefault ;
  44.  
  45.  
  46. /**\
  47. |**| ==============================================================================
  48. |**| PRIVATE FUNCTIONS
  49. |**| ==============================================================================
  50. \**/
  51.  
  52.  
  53. /*------------------------------------------------------------------------------*\
  54.     winUpdateMenusDefault
  55.  *------------------------------------------------------------------------------*
  56.         This routine enables any menus and menu items in the menu bar
  57.         which the application is responsible for handling.
  58.         It is called by:
  59.             InitMenuBar() which is called when the app is intited,
  60.             DoActivateEvent() which is called whenever a window is brought to front, and
  61.             CloseProcPtrs which are called whenever windows are closed 
  62. \*------------------------------------------------------------------------------*/
  63. static void winUpdateMenusDefault ( winHandle win ) 
  64. {
  65.     MenuHandle    theMenu ;
  66.     
  67.     // do the file menu
  68.     theMenu = GetMenuHandle ( mApple ) ;
  69.     EnableItem ( theMenu, kWholeMenu ) ;
  70.     EnableItem ( theMenu, iAbout ) ;    
  71.     
  72.     // do the file menu
  73.     theMenu = GetMenuHandle ( mFile ) ;
  74.     EnableItem ( theMenu, kWholeMenu ) ;
  75.     EnableItem ( theMenu, iNew ) ;
  76.  
  77.     // do the profiles menu
  78.     theMenu = GetMenuHandle ( mProfiles ) ;
  79.     EnableItem ( theMenu, kWholeMenu ) ;
  80.     EnableItem ( theMenu, iDefaultProf ) ;
  81.     EnableItem ( theMenu, iCSFolderPopup ) ;
  82.  
  83.     // do the profile lists menu
  84.     theMenu = GetMenuHandle ( mProfileLists ) ;
  85.     EnableItem ( theMenu, kWholeMenu ) ;
  86.     EnableItem ( theMenu, iCSFolder ) ;
  87.     EnableItem ( theMenu, iCSFolderMntr ) ;
  88.     EnableItem ( theMenu, iCSFolderPrtr ) ;
  89.     EnableItem ( theMenu, iCSFolderScnr ) ;
  90. }
  91.  
  92.  
  93. /*------------------------------------------------------------------------------*\
  94.     winMenuDefault
  95.  *------------------------------------------------------------------------------*
  96.         This is a MenuProcPtr for the About window.
  97.         This routine dispatches any menu commands that the window can handle
  98.         to the appropriate function.
  99.         For the About window, the only need menu command is File:Close 
  100.         This ProcPtr is envoked by CallWinMenuProc() which is called by:
  101.             HandleMenuCommand() which dispatches all menu events.
  102. \*------------------------------------------------------------------------------*/
  103. static void winMenuDefault ( winHandle win, long menuResult, Boolean *didit )
  104. {
  105.     short            menuID;
  106.     short            menuItem;
  107.     
  108.     *didit = true ;
  109.     menuID   = HiWrd(menuResult) ;
  110.     menuItem = LoWrd(menuResult) ;
  111.     switch ( menuID )
  112.     {
  113.         case mApple:
  114.             switch ( menuItem )
  115.             {
  116.                 case iAbout:
  117.                     DoAboutBoxCommand() ;
  118.                     break;
  119.                 default :
  120.                     *didit = false ;
  121.                     break ;
  122.             }
  123.             break;
  124.  
  125.         case mFile:
  126.             switch ( menuItem )
  127.             {
  128.                 case iNew:                // make a new document
  129.                     DoNewCommand() ;
  130.                     break;
  131.                     
  132.                 default :
  133.                     *didit = false ;
  134.                     break ;
  135.             }
  136.             break;
  137.             
  138.         case mProfiles:
  139.             switch ( menuItem )
  140.             {
  141.                 case iDefaultProf:
  142.                     DoDefaultProfCommand() ;
  143.                     break;
  144.                 default :
  145.                     *didit = false ;
  146.                     break ;
  147.             }
  148.             break;
  149.  
  150.         case mProfileLists:
  151.             switch ( menuItem )
  152.             {
  153.                 case iCSFolder:
  154.                     DoProfListCommand( 0 ) ;
  155.                     break;
  156.                 case iCSFolderMntr:
  157.                     DoProfListCommand('mntr') ;
  158.                     break;
  159.                 case iCSFolderPrtr:
  160.                     DoProfListCommand('prtr') ;
  161.                     break;
  162.                 case iCSFolderScnr:
  163.                     DoProfListCommand('scnr') ;
  164.                     break;
  165.                 default :
  166.                     *didit = false ;
  167.                     break ;
  168.             }
  169.             break;
  170.  
  171.         default :
  172.             *didit = false ;
  173.             break ;
  174.     }
  175.     HiliteMenu(0) ;        // Unhighlight whatever MenuSelect or MenuKey hilited
  176. }
  177.  
  178.  
  179.  
  180. /*------------------------------------------------------------------------------*\
  181.     DoNewCommand
  182.  *------------------------------------------------------------------------------*
  183.         This routine handles the File:New command for the application.
  184.         It is not yet implimented but in principle, it should create a new
  185.         winHandle, and call its OpenProcPtr got get it going.
  186.         It is called by:
  187.             HandleMenuCommand() which dispatches all menu events.
  188. \*------------------------------------------------------------------------------*/
  189. static void DoNewCommand ( void ) 
  190. {
  191.     OSErr            err = noErr ;
  192.     winHandle        win;
  193.  
  194.     // create a new winHandle of the propper type
  195.     err = NewWinHandle( &win, winAllocPictDoc ) ;
  196.     WarnIfErr( err ) ;
  197.     if (err) return ;
  198.  
  199.     err = CallWinNewProc( win ) ;
  200.     if ( err != noErr )
  201.         DisposeWinHandle( win ) ;
  202.  
  203.     if ( err == kWasAlreadyOpen )
  204.         err = noErr ;
  205. }
  206.  
  207.  
  208. /*------------------------------------------------------------------------------*\
  209.     DoAboutBoxCommand
  210.  *------------------------------------------------------------------------------*
  211.         This routine handles the Apple:About command for the application.
  212.         It creates a new winHandle, sets its NewProcPtr, and then 
  213.         calls the NewProcPtr to get it going.
  214.         It is called by:
  215.             HandleMenuCommand() which handles all menu events.
  216. \*------------------------------------------------------------------------------*/
  217. static void DoAboutBoxCommand ( void ) 
  218. {
  219.     OSErr            err = noErr ;
  220.     winHandle        win;
  221.  
  222.     // create a new winHandle of the propper type
  223.     err = NewWinHandle( &win, winAllocAbout ) ;
  224.     WarnIfErr( err ) ;
  225.     if (err) return ;
  226.  
  227.     err = CallWinNewProc( win ) ;
  228.     if ( err != noErr )
  229.         DisposeWinHandle( win ) ;
  230.  
  231.     if ( err == kWasAlreadyOpen )
  232.         err = noErr ;
  233. }
  234.  
  235.  
  236. /*------------------------------------------------------------------------------*\
  237.     DoDefaultProfCommand
  238.  *------------------------------------------------------------------------------*
  239.         This routine handles the Profile:Default Profile command for the application.
  240.         It creates a new winHandle, sets its OpenProcPtr, and then 
  241.         calls the OpenProcPtr to get it going.
  242.         It is called by:
  243.             HandleMenuCommand() which handles all menu events.
  244. \*------------------------------------------------------------------------------*/
  245. static void DoDefaultProfCommand ( void ) 
  246. {
  247.     OSErr            err = noErr ;
  248.     winHandle        win;
  249.                 
  250.     // create a new winHandle of the proper type
  251.     err = NewWinHandle( &win, winAllocProfile ) ;
  252.     WarnIfErr( err ) ;
  253.     if (err) return ;
  254.                 
  255.     SetProfileRef( win, nil ) ;
  256.     SetWinSubtype( win, kSysProfSubType ) ;    // set subtype
  257.                 
  258.     err = CallWinOpenProc( win ) ;
  259.     if ( err != noErr )            //if an error occured
  260.         DisposeWinHandle( win ) ;
  261.         
  262.     if ( err == kWasAlreadyOpen )
  263.         err = noErr;
  264. }
  265.  
  266.  
  267. /*------------------------------------------------------------------------------*\
  268.     DoProfListCommand
  269.  *------------------------------------------------------------------------------*
  270.         This routine handles the Profile:CS Folder command for the application.
  271.         It creates a new winHandle, sets its OpenProcPtr, and then 
  272.         calls the OpenProcPtr to get it going.
  273.         It is called by:
  274.             HandleMenuCommand() which handles all menu events.
  275. \*------------------------------------------------------------------------------*/
  276. static void DoProfListCommand ( OSType profileClass ) 
  277. {
  278.     OSErr            err = noErr ;
  279.     winHandle        win;
  280.     
  281.     // create a new winHandle of the proper type
  282.     err = NewWinHandle( &win, winAllocProfList ) ;
  283.     WarnIfErr( err ) ;
  284.     if (err) return ;
  285.  
  286.     // set the subtype of the winHandle so that the correct search is done
  287.     SetWinSubtype( win, profileClass ) ;    // set subtype
  288.     
  289.     err = CallWinNewProc( win ) ;
  290.     if ( err != noErr )
  291.         DisposeWinHandle( win ) ;
  292.  
  293.     if ( err == kWasAlreadyOpen )
  294.         err = noErr;
  295. }
  296.  
  297.  
  298.